#ifndef CVHTTP_H
#define CVHTTP_H

#include <QObject>
#include <QUrl>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QSslError>
#include <QtNetwork/QNetworkCookie>
#include <QByteArray>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptValue>
#include <QList>
#include <QTextCodec>


#include "cvsession.h"

class CVHttp : public QObject
{
    Q_OBJECT
public:
    CVHttp(QUrl url);
    CVHttp(QUrl url, QByteArray bytes);

    void setDebug(bool debug);
protected:
    QUrl mUrl;

signals:
    void readyRead();
    void downloadProgress(qint64 curbytes, qint64 total);
    void finished(QScriptValue result, const QString &message);
    void handleError(QNetworkReply::NetworkError error);
public slots:
    void readyReadSlot();
    void downloadProgressSlot(qint64 bytesReceived, qint64 total);
    void finishedSlot();
    void errorSlot(QNetworkReply::NetworkError error);
private slots:
    void ignoreSslError(QNetworkReply *, QList<QSslError>);
private:
    void initSlots();

    QNetworkAccessManager *manager;
    QNetworkReply *reply;

    bool debug;
};

#endif // CVHTTP_H
